< previous page page_50 next page >

Page 50
Save the form (DYNASETS.FRM) and project (DYNASETS.VBP) again and run the program. You see a message box telling you how many records are in the Recordset. Figure 3.3 shows the results of a typical run.
0050-01.jpg
Figure 3.3.
Displaying the
RecordCount of
a Recordset.
You can use the OpenRecordset command on an existing Recordset to create a smaller subset of the data. This is often done when the user is allowed to create a record selection criterion. If the dataset returned is too large, the user is allowed to further qualify the search by creating additional criteria to apply to the dataset.
Let's modify DYNASETS.VBP to create a smaller Dynaset-type Recordset from the existing Recordset. You need to create a new Recordset object and a new variable called strFilter to hold the criteria for selecting records. The code in Listing 3.5 shows how to add the object and variable to the existing DYNASETS.VBP project.
Type.gifListing 3.5. Adding a new Recordset object and string variable.
Private Sub Form_Load()
    '
    ' creating dynaset-type recordsets
    '
    Dim db As Database ' the database object
    Dim rs As Recordset ' the recordset object
    Dim rs2 As Recordset ' <<< add another recordset object
    '
    ' create local variables
    Dim strDBName As String
    Dim strRSName As String
    Dim intRecs As Integer
    Dim strFilter As String ' <<< add filter
    '
    ' initialize the variables
    strDBName = App.Path & "\..\data\books5.mdb"
    strRSName = "Titles"
    strFilter = "YearPub>1990" ' <<< set filter
    '
    ' create the objects
    Set db = DBEngine.OpenDatabase(strDBName)
    Set rs = db.OpenRecordset(strRSName, dbOpenDynaset)
    '
    ' count the records in the collection
    rs.MoveLast ' move to end of list to force a count

 
< previous page page_50 next page >

If you like this book, buy it!